﻿#region Using
#if NUNIT
using System;
using System.Collections;
using System.Data;
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestContext = System.Object;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Category = Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute;
#endif

using NMock2;
using NMock2.Matchers;

#endregion

namespace NMock3.Tests
{
	[TestClass]
	public class DoubleInterfaces
	{
		private MockFactory _factory;
		private Mock<IDisposable> _mock;

		public DoubleInterfaces()
		{
			_factory = new MockFactory();
		}

		[TestInitialize]
		public void TestInit()
		{
			_mock = _factory.CreateMock<IDisposable>(new[] { typeof(ICloneable), typeof(IDictionary) });
		}

		[TestCleanup]
		public void TestClean()
		{
			_factory.VerifyAllExpectationsHaveBeenMet();
		}


		[Test]
		public void Test1()
		{
			Mock<ICloneable> clone = _mock.As<ICloneable>();
			clone.Expects.One.Method(c => c.Clone()).WillReturn(new DataSet());

			Assert.IsTrue(clone.MockObject.Clone().GetType() == typeof(DataSet));
		}

		[Test]
		public void Test2()
		{
			Mock<IList> clone = _mock.As<IList>();
			Assert.IsNull(clone);
		}

		[Test]
		public void Test3()
		{
			Mock<IEnumerable> clone = _mock.As<IEnumerable>();
			clone.Expects.One.Method(c => c.GetEnumerator()).WillReturn(new Stack().GetEnumerator());

			Type type1 = clone.MockObject.GetEnumerator().GetType();
			Type type2 = typeof (IEnumerator);

			Assert.IsTrue(type2.IsAssignableFrom(type1));
		}

	}
}